package com.mayflygeek.mayflyask.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
/**
 * @author 蝈蝈 
 * @email guodefu909@126.com
 * @team 蜉蝣极客
 * @link www.mayflygeek.com
 * 缓存过滤器，禁止浏览器缓存网页
 */
public class NoCacheFilter implements Filter{

	@Override
	public void destroy() {
//		销毁
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
		
		HttpServletResponse hsr = (HttpServletResponse) res;
	    hsr.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1
	    hsr.setHeader("Pragma", "no-cache"); // HTTP 1.0
	    hsr.setDateHeader("Expires", 0); // Proxies
	    chain.doFilter(req, res);
		
	}

	@Override
	public void init(FilterConfig config) throws ServletException {
//		初始化
	}

}
